package capricornus.components.button
{
	import capricornus.components.label.Label;
	import capricornus.components.utils.FilterUtils;
	
	import flash.events.MouseEvent;
	
	public class LabelButton extends Label
	{
		/**
		 * 是否是单纯的发光按钮，默认是false 
		 */		
		private var _isGlowBtn:Boolean = false;
		
		private var _overColor:uint = 0xffffff;
		private var _downColor:uint = 0;
		private var _upColor:uint = 0xffff00;
		
		public function LabelButton()
		{
			super();
			init();
		}
		
		private function init():void
		{
			this.mouseChildren = false;
			this.underline = true;
			
			this.addEventListener( MouseEvent.MOUSE_OVER, onMouseOver, false, 0, true );
			this.addEventListener( MouseEvent.MOUSE_OUT, onMouseOut, false, 0, true );
			
			this.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown, false, 0, true );
			this.addEventListener( MouseEvent.MOUSE_UP, onMouseUp, false, 0, true );
		}
		
		/**
		 * 设置发光按钮
		 * 当设置发光按钮的时候，只需要设置up颜色，over颜色会以变亮滤镜代替，down变暗代替 
		 * @param upColor
		 * 
		 */		
		public function setGlowButton( upColor:uint ):void
		{
			_isGlowBtn = true;
			
			_upColor = upColor;
			_textField.textColor = upColor;
			_container.filters = null;
		}
		
		public function setColor( overColor:uint, downColor:uint, upColor:uint ):void
		{
			_overColor = overColor;
			_downColor = downColor;
			_upColor = upColor;
			
			_textField.textColor = _upColor;
			_container.filters = null;
		}
		
		private function onMouseOver( e:MouseEvent ):void
		{
			if( _isGlowBtn )
			{
				_container.filters = FilterUtils.getShineFilter(40);
			}
			else
				_textField.textColor = _overColor;
		}
		
		private function onMouseOut( e:MouseEvent ):void
		{
			_textField.textColor = _upColor;
			_container.filters = null;
		}
		
		private function onMouseDown( e:MouseEvent ):void
		{
			if( _isGlowBtn )
			{
				_container.filters = FilterUtils.getShineFilter( -40 );
			}
			else
				_textField.textColor = _downColor;
		}
		
		private function onMouseUp( e:MouseEvent ):void
		{
			if( _isGlowBtn )
			{
				_container.filters = FilterUtils.getShineFilter(40);
			}
			else 
			{
				_container.filters = null;
			}
			_textField.textColor = _upColor;	
		}
	}
}